home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_11 / phillip2 / gin.c < prev    next >
C/C++ Source or Header  |  1993-05-13  |  4KB  |  161 lines

  1.  
  2.         /*******************************************************
  3.         *
  4.         *       file d:\cips\gin.c
  5.         *
  6.         *       Functions: This file contains
  7.         *           get_image_name
  8.         *           get_directory_name
  9.         *           extract_base_image_name
  10.         *
  11.         *       Purpose - This function prompts the user to
  12.           *            enter the name of an image.
  13.         *
  14.         *       External Calls:
  15.         *                       clear_buffer
  16.         *
  17.         *       Modifications:
  18.         *           26 September 86 - now uses vision3.h
  19.         *               instead of vision2.h and the read_string
  20.         *               and get_integer instead of  scanf.
  21.         *           11 March 1987 - this function was
  22.         *               removed from the file ip.c and put
  23.         *               in file gin.c.
  24.         *
  25.         ******************************************************/
  26.  
  27.  
  28. #include "cips.h"
  29.  
  30.  
  31.  
  32.  
  33.    /*********************************************
  34.     *
  35.     * get_image_name(...
  36.     *
  37.     * This function reads in the desired image
  38.     * file name.
  39.     *
  40.     *********************************************/
  41.  
  42. get_image_name(name)
  43.    char name[];
  44. {
  45.    char base_name[80],
  46.         dir_name[80],
  47.         new_name[80],
  48.         response[80];
  49.    int  l;
  50.  
  51.    printf("\n\nImage name is--%s\n", name);
  52.    printf("\nDo you want to change:");
  53.    printf("\n (f) file name");
  54.    printf("\n (d) directory name");
  55.    printf("\n (n) no change");
  56.    printf("\n     _\b");
  57.    gets(response);
  58.  
  59.    if((response[0] == 'F') ||
  60.       (response[0] == 'f')){
  61.       printf("\n\nEnter file name (name only no extension)");
  62.       printf("\n--");
  63.       gets(new_name);
  64.       extract_directory_name(name, dir_name);
  65.       sprintf(name, "%s%s.tif", dir_name, new_name);
  66.    }
  67.  
  68.    if((response[0] == 'D') ||
  69.       (response[0] == 'd')){
  70.       printf("\n\nEnter directory name\n--");
  71.       gets(dir_name);
  72.       l = strlen(dir_name);
  73.       if(dir_name[l-1] != 47){
  74.          dir_name[l]   = '/';
  75.          dir_name[l+1] = '\0';
  76.       }
  77.       printf("\n\nEnter file name (name only no extension)");
  78.       printf("\n--");
  79.       gets(new_name);
  80.       sprintf(name, "%s%s.tif", dir_name, new_name);
  81.    }
  82.  
  83. }       /* ends get_image_name  */
  84.  
  85.  
  86.  
  87.  
  88.    /*********************************************
  89.     *
  90.     * extract_directory_name(...
  91.     *
  92.     * This function extracts the sub-directory
  93.     * name out of a file name.
  94.     *
  95.     *********************************************/
  96.  
  97. extract_directory_name(file_name, dir_name)
  98.    char file_name[], dir_name[];
  99. {
  100.    int i, j, k;
  101.  
  102.    i = 1;
  103.    j = 0;
  104.    k = 0;
  105.    while(i){
  106.       if(file_name[k] == 47  ||
  107.          file_name[k] == 92)     j = k;
  108.       if(file_name[k] == '\0')   i = 0;
  109.       k++;
  110.    }
  111.    j++;
  112.    strncpy(dir_name, file_name, j);
  113.    dir_name[j] = '\0';
  114.  
  115. }  /* ends extract_directory_name */
  116.  
  117.  
  118.  
  119.  
  120.  
  121.    /*********************************************
  122.     *
  123.     *   extract_base_image_name(...
  124.     *
  125.     *   This function looks at a full file name
  126.     *   and pulls off the sub-directory name and
  127.     *   the file extension and returns the base
  128.     *   file name.
  129.     *
  130.     *********************************************/
  131.  
  132. extract_base_file_name(file_name, base_name)
  133.    char base_name[], file_name[];
  134. {
  135.    int i, j, k;
  136.    i = 1;
  137.    j = 0;
  138.    k = 0;
  139.    while(i){
  140.       if(file_name[k] == 47  ||
  141.          file_name[k] == 92)     j = k;
  142.       if(file_name[k] == '\0')   i = 0;
  143.       k++;
  144.    }
  145.  
  146.    i = 1;
  147.    k = 0;
  148.    j++;
  149.    while(i){
  150.       if(file_name[j] == '.')
  151.          i = 0;
  152.       else
  153.          base_name[k] = file_name[j];
  154.       j++;
  155.       k++;
  156.    }
  157.    k--;
  158.     base_name[k] = '\0';
  159. printf("\nEBN> base is %s", base_name);
  160. }  /* ends extract_base_file_name */
  161.